package com.unitechs.commons.utils;

import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;

//TODO 开发中
public class ZyucAutoCloseableDocument implements Closeable {

    private final Document document;

    public ZyucAutoCloseableDocument(OutputStream outputStream) {
        this.document = new Document();
        try {
            PdfWriter.getInstance(document, outputStream);
            document.open();
        } catch (Exception e) {
            throw new RuntimeException("Error opening the document", e);
        }
    }

    @Override
    public void close() throws IOException {
        if (document != null && document.isOpen()) {
            document.close();
        }
    }

    public Document getDocument() {
        return document;
    }
}
